package com.bawei.test.builder;

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/22 10:50
 * @Description : Computer
 */
public class Computer {
    //1：定义属性
    private  String cpu;
    private  String ram;
    private  int usbCount;
    private  String keyboard;
    private  String display;
    //5:Computer构造，传入Builder对象
    public Computer(Builder builder) {
        this.cpu = builder.cpu;
        this.ram = builder.ram;
        this.usbCount = builder.usbCount;
        this.keyboard = builder.keyboard;
        this.display = builder.display;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "cpu='" + cpu + '\'' +
                ", ram='" + ram + '\'' +
                ", usbCount=" + usbCount +
                ", keyboard='" + keyboard + '\'' +
                ", display='" + display + '\'' +
                '}';
    }

    //2：静态内部类
    public static class Builder{
        //3:定义属性并提供set方法
        private  String cpu = "默认cpu";
        private  String ram = "默认ram";
        private  int usbCount = 2;
        private  String keyboard = "默认keyboard";
        private  String display = "默认display";
//        //设置默认值
//        public Builder() {
//            cpu = "默认cpu";
//            ram = "默认ram";
//            usbCount = 2;
//            keyboard = "默认keyboard";
//            display = "默认display";
//
//        }


        public Builder setCpu(String cpu) {
            this.cpu = cpu;
            return this;
        }

        public Builder setRam(String ram) {
            this.ram = ram;
            return this;
        }

        public Builder setUsbCount(int usbCount) {
            this.usbCount = usbCount;
            return this;
        }

        public Builder setKeyboard(String keyboard) {
            this.keyboard = keyboard;
            return this;
        }

        public Builder setDisplay(String display) {
            this.display = display;
            return this;
        }
        //4：提供build()方法
        public Computer build(){
            return new Computer(this);
        }
    }

}
